<?php

namespace app\common\model\order;

use think\Model;


class Refund extends Model
{





    // 表名
    protected $name = 'order_refund';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'teketime_text',
        'refund_status_text',
        'refund_type_text',
        'express_images_array',
        'images_array',
    ];
    public function getExpressImagesArrayAttr($v, $d)
    {
        if (isset($d['express_images']) && $d['express_images']) {
            $array = explode(',', $d['express_images']);
            foreach ($array as &$value) {
                $value = $value ? cdnurl($value, true) : '';
            }
            return $array;
        }
        return [];
    }
    public function getImagesArrayAttr($v, $d)
    {
        if (isset($d['images']) && $d['images']) {
            $array = explode(',', $d['images']);
            foreach ($array as &$value) {
                $value = $value ? cdnurl($value, true) : '';
            }
            return $array;
        }
        return [];
    }

    public function getRefundStatusList()
    {
        return ['10' => __('Refund_status 10'), '20' => __('Refund_status 20'), '-1' => __('Refund_status -1')];
    }

    public function getRefundTypeList()
    {
        
        return ['1' => __('Refund_type 1'), '2' => __('Refund_type 2')];
    }
    

    public function getTeketimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['teketime']) ? $data['teketime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getRefundStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['refund_status']) ? $data['refund_status'] : '');
        $list = $this->getRefundStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getRefundTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['refund_type']) ? $data['refund_type'] : '');
        $list = $this->getRefundTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setTeketimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


    public function user()
    {
        return $this->belongsTo('app\common\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    public function goods()
    {
        return $this->belongsTo('app\common\model\goods\Goods', 'goods_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
